package com.fishery.base.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fishery.base.entity.Catch;
import com.fishery.base.service.CatchService;
import com.fishery.entity.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 捕捞记录前端控制器
 * </p>
 *
 * @author Ghost
 * @since 2021-01-30
 */
@RestController
@RequestMapping("/base/catch")
@CrossOrigin
@Api(tags = "种苗捕捞信息管理模块")
public class CatchController {

	@Autowired
	private CatchService catchService;


	@GetMapping("/{baseId}/{size}/{current}")
	@ApiOperation("查询基地的种苗已捕捞信息(带分页)")
	public Result getCatchRecords(@PathVariable(name = "baseId", required = true) @ApiParam(required = true, value = "基地ID") String baseId,
								  @PathVariable(name = "size", required = true) @ApiParam(required = true, value = "尺寸") int size,
								  @PathVariable(name = "current", required = true) @ApiParam(required = true, value = "页码") int current) {
		if (StringUtils.isEmpty(baseId)) {
			return Result.error("查询失败");
		}
		Page<Catch> page = catchService.pageCatchRecords(baseId, size, current);
		return Result.success().data(page);
	}

	@DeleteMapping("/{id}")
	@ApiOperation("删除已捕捞捕捞信息")
	public Result deleteCatchRecord(@PathVariable(name = "id", required = true) @ApiParam(required = true, value = "id") String id) {
		if (StringUtils.isEmpty(id)) {
			return Result.error("删除失败");
		}
		boolean ret = catchService.removeById(id);
		return ret ? Result.success("删除成功") : Result.error("删除失败");
	}

}
